<template>
  <el-dialog
    title="日志列表"
    :close-on-click-modal="false"
    :visible.sync="lodDialogVisible"
    width="75%">
    <el-form :inline="true" v-model="dataForm">
      <el-form-item label="公司名称">
        <el-input v-model="dataForm.tenantName" clearable @clear="clickSearch"></el-input>
      </el-form-item>
      <el-form-item label="信用代码">
        <el-input v-model="dataForm.certificateCode" clearable @clear="clickSearch"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="clickSearch">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      height="460"
      border
      v-loading="dataListLoading">
      <el-table-column prop="tenantName" label="公司名称" ></el-table-column>
      <el-table-column prop="certificateCode" label="信用代码"></el-table-column>
      <el-table-column prop="" label="联系方式" width="120px">
        <template slot-scope="scope">
          {{scope.row.contactPersonMobile ? scope.row.contactPersonMobile :  scope.row.contactPersonTel ? scope.row.contactPersonTel : ''}}
        </template>
      </el-table-column>
      <el-table-column v-for="certificateCountItem in dataList[0].certificateCountList" prop="" width="80px"  :label="certificateCountItem.name">
        <template slot-scope="scope">
          {{getCertificateByName(scope.row.certificateCountList, certificateCountItem.name)}}
        </template>
      </el-table-column>
      <el-table-column prop="" label="最近一次登录" width="110px" show-overflow-tooltip>
        <template slot-scope="scope">
          <span v-if="scope.row.lastLoginUserName">{{scope.row.lastLoginUserName}}({{scope.row.lastLoginTime}})</span>
        </template>
      </el-table-column>
      <el-table-column prop="thisMonthLoginTimes" label="本月登录次数" width="110px"></el-table-column>
      <el-table-column prop="lastMonthLoginTimes" label="上月登录次数" width="110px"></el-table-column>

      <!--      <template slot-scope="scope">
        <el-table-column v-for="certificateCountItem in scope.row.certificateCountList" :label="certificateCountItem.name">
          {{scope.row.amount}}
        </el-table-column>
      </template>-->
      </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageInfo.pageIndex"
      :page-sizes="[10, 20, 50]"
      :page-size="pageInfo.pageSize"
      :total="pageInfo.totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
  </el-dialog>
</template>

<script>
import {getTenantCountLog} from '../../../api/sys'

export default {
  name: 'TenantInfoLog',
  data () {
    return {
      dataForm: {
        certificateCode: '',
        tenantName: '',
        businessEntity: '',
        businessEntityMobile: ''
      },
      dataList: [
        {
          'tenantId': 94,
          'type': null,
          'tenantName': '浙江顶秀建筑有限公司',
          'certificateCode': '91330106MA28NAW47F',
          'registeredCapital': null,
          'businessEntity': null,
          'businessEntityTel': null,
          'businessEntityMobile': null,
          'businessEntityEmail': null,
          'contactPerson': '13675891234',
          'contactPersonTel': null,
          'contactPersonMobile': '13675891234',
          'region': null,
          'address': null,
          'zip': null,
          'certificatePicPath': null,
          'orgCertificatePicPath': null,
          'status': 1,
          'createBy': null,
          'createTime': '2021-04-07 18:08:08',
          'updateBy': null,
          'updateTime': null,
          'thisMonthLoginTimes': 0,
          'lastMonthLoginTimes': 0,
          'lastLoginUserName': '张三',
          'lastLoginTime': '2021-04-07 18:08:08',
          'certificateCountList': [
            {
              'amount': 2,
              'tenantId': 94,
              'name': '现场岗位人员'
            },
            {
              'amount': 3,
              'tenantId': 94,
              'name': '注册人员'
            },
            {
              'amount': 4,
              'tenantId': 94,
              'name': '职称人员'
            },
            {
              'amount': 5,
              'tenantId': 94,
              'name': '三类人员'
            }
          ]
        }
      ],
      lodDialogVisible: false,
      dataListLoading: false,
      pageInfo: {
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0
      }
    }
  },
  created () {
    // this.getDataList()
  },
  methods: {
    async init () {
      this.lodDialogVisible = true
      await this.getDataList()
    },
    sizeChangeHandle (val) {
      this.pageInfo.pageSize = val
      this.pageInfo.pageIndex = 1
      this.getDataList()
    },
    currentChangeHandle (val) {
      this.pageInfo.pageIndex = val
      this.getDataList()
    },
    getDataList () {
      let condition = {
        'tenantId': null,
        'tenantName': this.dataForm.tenantName,
        'certificateCode': this.dataForm.certificateCode,
        'businessEntity': this.dataForm.businessEntity,
        'businessEntityMobile': this.dataForm.businessEntityMobile
      }
      this.dataListLoading = true
      getTenantCountLog(
        {conditions: condition,
          inOrder: null,
          orderBy: null,
          pageNum: this.pageInfo.pageIndex,
          pageSize: this.pageInfo.pageSize
        },
        ({data}) => {
          console.log('data', data)
          this.dataList = data.records
          this.pageInfo.totalPage = data.total
          this.dataListLoading = false
        },
        () => {
          this.dataListLoading = false
        }
      )
    },
    clickSearch () {
      this.pageInfo.pageIndex = 1
      this.getDataList()
    },
    getCertificateByName (certificateList, name) {
      let certificate = certificateList.find(item => item.name === name)
      if (certificate) {
        return certificate.amount
      } else {
        return ''
      }
    }

  }
}
</script>

<style scoped>

</style>
